// Copyright 2011, Vanya Davidenko.
// Кодировка файла: UTF-8. 
package info.iu9.red;

import java.util.Arrays;



class DfaCachedState {
  static DfaCachedState make(final StateIdSetList s,
                             final boolean matched,
                             final int max_nexts) {
    return new DfaCachedState(Arrays.copyOf(s.dense(), s.size()),
                              matched,
                              max_nexts);
  }

  int[] dense() {
    return dense_;
  }
  int size() {
    return dense_.length;
  }

  int sizeInBytes() {
    return dense_.length * 4 + 12;
  }

  DfaCachedState next(final int c) {
    return nexts_[c];
  }
  void set_next(final DfaCachedState next, final int c) {
    assert next != null;
    nexts_[c] = next;
  }

  boolean matched() {
    return matched_;
  }

  boolean isEmpty() {
    return dense_.length == 0;
  }

  void restoreTo(final StateIdSetList s) {
    s.clear();
    for ( final int i : dense_ ) {
      s.pushNew(i);
    }
  }

  public int hashCode() {
    throw new UnsupportedOperationException();
  }
  public boolean equals(Object o) {
    throw new UnsupportedOperationException();
  }


  private DfaCachedState(final int[] dense,
                         final boolean matched,
                         final int max_nexts) {
    assert dense != null;
    dense_ = dense;
    matched_ = matched;
    nexts_ = new DfaCachedState[max_nexts];
  }

  private final int[] dense_;
  private final boolean matched_;
  private final DfaCachedState[] nexts_;
}
